/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistema.medico.datos;

/**
 *
 * @author ALDEL
 */
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.config.EmbeddedConfiguration;

public class DataConnection {
    private static DataConnection dataBase = null;
    private final String PATH = "Sistema_Medico.db4o";//Este es el nombre del fichero donde
    private static ObjectContainer db;
    private DataConnection() {
        
    }
    private synchronized static void createInstance() {
        if (dataBase == null) {
            dataBase = new DataConnection();
            dataBase.performConnection();
        }
    }  //De aquí cojemos la conexión
    public static ObjectContainer getInstance() {
        if (dataBase == null) {
            createInstance();
        }
        return db;
    }
    public void performConnection() {
        EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
        db = Db4oEmbedded.openFile(config, PATH);
    }
    //Cerramos la conexión
    public void closeConnection() {
        db.close();
    }
    
}